PORT = '5001';
WEB_NAME = "essc_m_wx"

HOST = 'www.lxyuan.net';
const APP_NAME = 'essc'; //essc
axios.defaults.baseURL = 'http://' + HOST + ':' + PORT + '/' + APP_NAME + '/';
const HOME_HOST = 'http://' + HOST + '/';
const APP_SERVICE = 'service';
const APP_DESKPTOP = 'desktop';
const PAGE_LOGIN = 'login.html';
const DOWNLOAD_PATH =axios.defaults.baseURL+ "api/image/download/workorder"
const DOWNLOAD_INNERWORKERORDER_PATH =axios.defaults.baseURL+"api/image/download/innerworkorder"
const DOWNLOAD_KEEPACCOUNT_PATH =axios.defaults.baseURL+"api/image/download/keepaccount"
/*
*use in
* essc_m_wx/service/js/lottery.js 1:21
*
*/
WEB_HOME = HOME_HOST + WEB_NAME
const EXAM = 'examination.html';

const QRCODE = WEB_HOME + '/' + APP_SERVICE + '/' + 'applicant_details.html?'

const QRFIRSTCODE = WEB_HOME + '/' + APP_SERVICE + '/' + 'applicant_registration.html'

const P_DESKTOP= WEB_HOME + '/' + APP_SERVICE + '/' + 'p_desktop.html';
//use in essc_m_wx/service/js/discount_list.js 85
const STATUSTYPE=[{
	value: '待审核',
	label: '待审核'
}, {
	value: '已审核',
	label: '已审核'
}, {
	value: '已作废',
	label: '已作废'
}]
//use in essc_m_wx/service/js/mytest.js
const STATETYPE = [{
	value: '待开始',
	label: '待开始'
}, {
	value: '进行中',
	label: '进行中',
	disabled: true
}, {
	value: '已结束',
	label: '已结束',
	disabled: true
}];
const TAXTYPEOPTIONS =[
            {
				value: '个体工商户',
				label: '个体工商户'
			},
            {
				value: '小规模',
				label: '小规模'
			},
			{
				value: '一般纳税人',
				label: '一般纳税人',
			}
			];
/*
*use essc_m_wx/service/js/workorder.js 192:1
*use essc_m_wx/service/js/keep_account.js 498:1
*/
const WORKORDERSTATUS =[{
				value: '未完成',
				label: '未完成'
			},  {
				value: '已完成',
				label: '已完成',
			}];
/*
*use essc_m_wx/service/js/myregistrator.js 176:21
* */
const MYLOCALTYPE=[{
	value: '无锡',
	label: '无锡'
},{
	value: '徐州',
	label: '徐州'
},{
	value: '绍兴',
	label: '绍兴'
}]

/*
*use essc_m_wx/service/js/applicant_registration.js 28:12
*use essc_m_wx/service/js/applicant_details.js 39:12
* */
const POSITIONTYPE = ['财税顾问','工商助理','工商顾问','市场专员', '程序员', '外勤会计', '会计助理', '做账会计'];
/*
*use essc_m_wx/service/js/applicant_registration.js 30:12
*use essc_m_wx/service/js/applicant_details.js 39:12
* */

const LOCALTYPE = ['无锡','徐州', '绍兴'];
/*
*use essc_m_wx/service/js/keep_account 311
* */
const AGENTKEEPNAME="代理记账"
/*
*use essc_m_wx/service/js/workorder 555
* */
const REGISTER="注册"

/*
*use essc_m_wx/service/js/applicant_details.js 39:12
* */
const MYPOSITIONTYPE = [{
	value: '市场专员',
	label: '市场专员'
}, {
	value: '外勤会计',
	label: '外勤会计'
}, {
	value: '会计助理',
	label: '会计助理'
}, {
	value: '做账会计',
	label: '做账会计'
}, {
	value: '程序员',
	label: '程序员'
}];

/*
*use essc_m_wx/service/js/myquestion.js 63
* */
const MYQUESTIONTYPE = [{
	value: '单选',
	label: '单选'
}, {
	value: '多选',
	label: '多选'
}];
// const CONST_AREAS = ["无锡","江阴","宜兴","绍兴","徐州"];
// let cur_url=window.location.href;
// let path=cur_url.split('/')
// let cur_html=path[path.length-1]

//请求拦截
axios.interceptors.request.use(
	config => {
		config.headers["x-requested-with"] = 'XMLHttpRequest';
		config.headers["Token"] = localStorage.getItem('TOKEN');
		config.headers["UserID"] = localStorage.getItem('USERID');
		return config
	},
	error => {
		return Promise.reject(error)
	}
);
// 响应拦截器
axios.interceptors.response.use(
	response => {
		let data = response.data;
		if (data['code'] && data['code'] === -1) {
			throw new Error(response['data']['msg']);
		} else {
			if (data['code'] == 300) {
				//error.message = "授权失效，请重新登录！";
				alert("授权失效，请重新登录！")
				window.parent.location.href = HOME_HOST + APP_NAME + '/' + APP_SERVICE + '/' + PAGE_LOGIN;
			}
		}
		return data;
	},
	error => {
		if (error && error.response) {
			switch (error.response.status) {
				case 400:
					error.message = getErrMsg400(error);
					// error.message = '请求参数错误, 请刷新重试！';
					break;
				case 401:
					error.message = '授权失败，请重新登录！';
					break;
				case 403:
					error.message = '无权限操作，拒绝访问！';
					break;
				case 404:
					error.message = `请求地址不存在`;
					break;
				case 408:
					error.message = '请求超时';
					break;
				case 500:
					error.message = '服务器内部错误, 请联系管理员！';
					break;
				case 505:
					error.message = 'HTTP版本不受支持';
					break;
				default:
					error.message = error.response.status + ": 未知错误"
			}
		}
		return Promise.reject(error)
	}
);

function getErrMsg400(err) {
	let msg = "";
	let data = err.response.data;
	for (let key in data) {
		msg += data[key];
	}
	return msg;
}
//转义字符转换普通字符的方法
function escape2Html(str) {
	var arrEntities = {
		'lt': '<',
		'gt': '>',
		'nbsp': ' ',
		'amp': '&',
		'quot': '"',
		'&apos': '\''
	};
	return str.replace(/&(lt|gt|nbsp|amp|quot|apos);/ig, function(all, t) {
		return arrEntities[t];
	});
}
//普通字符转换成转义字符的方法
function html2Escape(str) {
	return str.replace(/[<>&"\']/g, function(c) {
		return {
			'<': '&lt;',
			'>': '&gt;',
			'&': '&amp;',
			'"': '&quot;',
			'\'': '&apos;'
		} [c];
	});
}

function deepCopy(Object) {
	return JSON.parse(JSON.stringify(Object));
}

const LOAD_STYLE = {
	lock: true,
	text: '加载中...',
	spinner: 'el-icon-loading',
	background: 'rgba(0, 0, 0, 0.7)'
}

const constIntRule = {
		type: 'number',
		message: '请输入整数',
		trigger: 'blur',
		transform(value) {
		  if(value !== null && value !== '') {
			if (String(value).trim() === '' || Number(value) < 0) {
			  return false
			}else if (String(value).indexOf('.') !== -1 || String(value).indexOf('-') !== -1) {
			  return false
			}else{
			  return Number(value)
			}
		  }else {
			return null
		  }
		}
}

